package com.aizuda.boot.modules.third.wps.service;

import com.aizuda.boot.modules.system.entity.SysUser;
import com.aizuda.boot.modules.system.service.ISysUserService;
import com.aizuda.boot.modules.third.wps.domain.vo.UserVo;
import com.aizuda.boot.modules.third.wps.enums.WebOfficeErrEnum;
import com.aizuda.boot.modules.third.wps.exception.WebOfficeException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author hjw
 * @description 获取用户信息Service
 * @date 2025年06月17日 18:28
 */
@Service
public class UserService {

    @Autowired
    private ISysUserService userService;


    /**
     * 根据用户 ID 列表获取用户信息
     *
     * @param userIds 用户 ID 列表
     * @return List < UserVo>
     */
    public List<UserVo> getUsers(List<Long> userIds) {
        List<SysUser> list = userService.lambdaQuery()
                .in(SysUser::getId, userIds)
                .list();
        if (list.isEmpty()) {
            throw new WebOfficeException(WebOfficeErrEnum.USER_NOT_FOUND);
        }
        // 将 EmployeeShowVO 转换为 UserVo
        List<UserVo> userVoList = list.stream()
                .map(employee -> UserVo.builder()
                        .id(employee.getId().toString())
                        .name(employee.getNickName())
                        .avatarUrl(employee.getAvatar())
                        .build())
                .collect(Collectors.toList());

        return userVoList;

    }
}
